<template>
	<view v-if="msg==''">
		<xbd-zwnz marginTop='200'></xbd-zwnz>
	</view>
	<view v-else class="center">
		<view class="title">
			{{msg.title}}
		</view>
		<view class="details">
			<view class="">
				<view class="tag">
					发布人：{{msg.creator}}
				</view>
				<view class="tag">
					发布时间：{{msg.created_at | timeFormat('YYYY-MM-DD HH:mm')}}
				</view>
				<view class="tag">
					阅读量：{{msg.read+1}}
				</view>
			</view>
			<view v-if="!isClick" class="collection" @click="collection">
				<view class="butn">
						<img class="image" src="@/static/image/index/news/collection2.png" alt="">
					<view>收藏</view>
				</view>
			</view>
			<view v-else class="collection click" @click="collection">
				<view class="butn">
						<img class="image" src="@/static/image/index/news/collection1.png" alt="">
					<view>已收藏</view>
				</view>
			</view>
		</view>
		<!-- 富文本编译插件 -->
		<parser :html="msg.content" :tagStyle='style'/>
	</view>
</template>

<script>
	import parser from '@/components/jyf-parser/jyf-parser.vue';
	import {
		Personalcenter
	} from '@/api/index.js';
	export default {
		
		data() {
			return {
				id:'',
				isClick:false,
				style: {
				    'img': 'display:block;margin: 0 auto;max-width:100%;height:auto; transform: translateX(0);',
					'video': 'width:100%;height:auto;',
				},
				msg:{}
			};
		},
		components: {
			parser
		},
		methods:{
			async collection(){
				
				if(!this.isClick){
					const res = await Personalcenter.posCollectionCreate(this.id)
					console.log(res)
					this.isClick = !this.isClick
				}else{
					const res = await Personalcenter.posCollectionCancel(this.id)
					this.isClick = !this.isClick
				}
			},
				
			async init(){
				const res = await Personalcenter.getCollectionDetail(this.id)
				console.log(res)
				this.msg = res.data
				this.isClick = this.msg.collection
				if(res.code == 9007){
					this.$showToast(res.msg);
				}
			},
			
		},
		async onLoad(res){
			console.log(res)
			this.id= res.id
				
			await this.init()
		}
	}
</script>

<style lang="scss" scoped>
	
.center{
	padding: 32rpx;
	.title{
		font-family: PingFang SC, PingFang SC-Heavy;
		font-weight: 800;
		line-height: 56rpx;
		font-size: 32rpx;
		color: #000623;
		text-align: justify;
		word-wrap: break-word;
		}
	.details{
		margin-top: 20rpx 0;
		padding-bottom: 40rpx;
		display:flex;
		justify-content: space-between;
		font-size: 26rpx;
		color: #8890A5;
		align-items: center;
		border-bottom: 2rpx solid #EBEEF5;
		margin-bottom: 20rpx;
		.tag{
			margin-bottom: 10rpx;
		}
		.collection{
			width: 144rpx;
			height: 56rpx;
			border: 2rpx solid #2E73FC;
			border-radius: 30rpx;
			.butn{
				height: 56rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #2E73FC;
				.image{
					width: 24rpx;
					height: 24rpx;
					margin-right: 8rpx;
					
				}
			}
				
			&.click{
				border: 2rpx solid #D0D6E5;
					
				.butn{
					color:#8890A5
				}
			}
		}
	}
}
</style>
